package io.renren.msg.client;

import io.renren.msg.HelloAbsAioHandler;
import io.renren.msg.HelloPacket;
import org.tio.client.intf.ClientAioHandler;
import org.tio.core.ChannelContext;

/**
 * Created by kun on 2017/5/2.
 */
public class HelloClientAioHandler extends HelloAbsAioHandler implements ClientAioHandler<Object,HelloPacket,Object> {
    private static HelloPacket heartbeatPacket=new HelloPacket();
    @Override
    public HelloPacket heartbeatPacket() {
        return heartbeatPacket;
    }

    @Override
    public Object handler(HelloPacket packet, ChannelContext<Object, HelloPacket, Object> channelContext) throws Exception {
        byte[] body=packet.getBody();
        if (body!=null){
            String str=new String(body,HelloPacket.CHARSET);
            System.out.println("客户端收到消息:"+str);
        }
        return null;
    }
}
